package main

import (
	"fmt"
	"log"
	"os"

	obj "ifile/object"
	"ifile/object/handle"
	obs "ifile/object/server"
)

var config *obj.Config

func init() {
	var err error

	config, err = obj.LoadObjectConfig("config.ini")
	if err != nil {
		log.Fatal(err)
	}

	_, err = os.Stat(config.RootPath)
	if err != nil {
		os.MkdirAll(config.RootPath, os.ModePerm)
	}
}

func main() {

	fileHandler := handle.MakeFileHandler(config.RootPath)

	httpServer := obs.MakeHTTPServer(config.RootPath)
	tcpServer := obs.MakeTCPServer(fmt.Sprintf(":%v", config.TCPPort))

	go tcpServer.ListenAndServe(fileHandler)
	httpServer.Api.Start(fmt.Sprintf(":%v", config.HttpPort))
}
